import {onBeforeUnmount, onMounted, reactive} from "vue"

export default function useMouseMove() {
    //定义data
    const data = reactive({ x: 0, y: 0 })
    //定义methods
    const updateMouse = (e) => {
        data.x = e.pageX;
        data.y = e.pageY;
    }
    //定义生命周期钩子函数
    onMounted(() => window.addEventListener("mousemove", updateMouse))
    onBeforeUnmount(() => window.removeEventListener("mousemove", updateMouse))
    //将模板中要使用的数据导出
    return {
        data,
    }
}